﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using WOWA.Core;
using WOWA.Model;
using WOWA.Model.Servers;
using Newtonsoft.Json;
using WOWA.Model.Characters;

namespace WOWA.UI
{
	public partial class AddCharacterPage : PhoneApplicationPage
	{
		public AddCharacterPage()
		{
			InitializeComponent();
		}

		private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
		{
			Reset();
		}

		private void Reset()
		{
			// add test data
#if DEBUG
			this.realm.Text = "玛诺洛斯";
			this.character.Text = "泰蘭德風語";
#endif
		}

		private void searchButton_Click(object sender, EventArgs e)
		{
			if (string.IsNullOrEmpty(realm.Text)
				|| string.IsNullOrEmpty(character.Text))
			{
				MessageBox.Show("请输入服务器及角色信息。");
				return;
			}

			//this.searchButton.IsEnabled = false;
			this.loadingPanel.Visibility = System.Windows.Visibility.Visible;
			this.characterPanel.Visibility = System.Windows.Visibility.Collapsed;

			CharacterLogic.GetCharacter(region.SelectedItem, realm.Text, character.Text, (data) =>
				{


					//this.searchButton.IsEnabled = true;
					this.loadingPanel.Visibility = System.Windows.Visibility.Collapsed;
					this.characterPanel.Visibility = System.Windows.Visibility.Visible;
				});
		}

		private void saveButton_Click(object sender, EventArgs e)
		{

		}

		private void cancelButton_Click(object sender, EventArgs e)
		{

		}
	}
}